namespace DotNetNuke.Services.FileSystem
{
    using DotNetNuke.Common;
    using DotNetNuke.Common.Utilities;
    using DotNetNuke.Entities.Portals;
    using DotNetNuke.Services.Exceptions;
    using DotNetNuke.Services.Scheduling;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;

    public class SynchronizeFileSystem : SchedulerClient
    {
        public SynchronizeFileSystem(ScheduleHistoryItem objScheduleHistoryItem)
        {
            this.ScheduleHistoryItem = objScheduleHistoryItem;
        }

        public override void DoWork()
        {
            try
            {
                this.Progressing();
                this.Synchronize();
                this.ScheduleHistoryItem.Succeeded = true;
                this.ScheduleHistoryItem.AddLogNote("File System Synchronized.");
            }
            catch (Exception exception1)
            {
                
                Exception exc = exception1;
                this.ScheduleHistoryItem.Succeeded = false;
                this.ScheduleHistoryItem.AddLogNote("File System Synchronization failed. " + exc.ToString());
                this.Errored(ref exc);
                DotNetNuke.Services.Exceptions.Exceptions.LogException(exc);
                
            }
        }

        private void Synchronize()
        {
            ArrayList arrPortals = new PortalController().GetPortals();
            FileSystemUtils.Synchronize(Null.NullInteger, Null.NullInteger, Globals.HostMapPath);
            int refIntHelperL0 = arrPortals.Count - 1;
            for (int intIndex = 0; intIndex <= refIntHelperL0; intIndex++)
            {
                PortalInfo objPortal = (PortalInfo) arrPortals[intIndex];
                FileSystemUtils.Synchronize(objPortal.PortalID, objPortal.AdministratorRoleId, objPortal.HomeDirectoryMapPath);
            }
        }
    }
}

